<template>
  <div style="margin-left: 550px">
    <form>
      <table ng="0" cellpadding="10" style="width: 500px">
        <tr>
          <td style="width: 100px">认证方式：</td>
          <td><div><el-input v-model="teacher.authmethod" placeholder="请输入内容" disabled="true" ></el-input></div></td>
        </tr>
        <tr>
          <td>姓名：</td>
          <td><el-input v-model="teacher.realname" placeholder="请输入内容" ></el-input></td>
        </tr>
        <tr>
          <td>证件号码：</td>
          <td><el-input v-model="teacher.authnum" placeholder="请输入内容" ></el-input></td>
        </tr>
        <tr>
          <td>学校：</td>
          <td><el-input v-model="teacher.school" placeholder="请输入内容" ></el-input></td>
        </tr>
        <tr>
          <td>职位：</td>
          <td><el-input v-model="teacher.posi" placeholder="请输入内容" ></el-input></td>
        </tr>
        <tr>
          <td>上传资质文件：</td>
          <td><el-upload
            class="upload-demo"
            action='http://localhost:8080/teacher/updateQualification'
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :file-list="fileList"
            :headers="headers1"
            list-type="picture">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
          </el-upload></td>
        </tr>
      </table>
    </form>
    <el-button type="success" plain @click="updateinfo()">保存修改</el-button><br>

  </div>
</template>

<script>
import router from "../../router";
import teacher from "./teacher";

export default {
  data(){
    return{
      teacher: {},
      teacherinfo:{
        authnum:teacher.authnum,
        realname:teacher.realname,
        posi:teacher.posi,
        school:teacher.school
      },
      fileList: [],
      headers1: {authorization: sessionStorage.getItem("token")}

    }
  },
  created(){
    //发送请求获取数据
    this.axios.get(this.baseUrl+"teacher/findById")
      .then(res =>{
        //res.data   ResponseResult
        console.log(res.data.data);
        //
        if (res.data.data == null) {
          this.teacher={
            authmethod:"身份证",
            authnum:"",
            realname:"",
            posi:"",
            school:""
          }
        }else{
          this.teacher= {
            authmethod: res.data.data.authmethod,
            authnum: res.data.data.authnum,
            realname: res.data.data.realname,
            posi: res.data.data.posi,
            school: res.data.data.school
          }
        }
      });
  },

  methods: {
    updateinfo: function () {
      console.log(this.teacherinfo)
      var configs = {
        headers: {'Content-Type': 'multipart/form-data'}
      };
      this.axios.post(this.baseUrl + "teacher/updateauth", this.teacher)
        .then(res => {
        })

    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    }
  },

}
</script>
<style scoped>
.el-header {
  background-color: #B3C0D1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>
